import {
	defineStore
} from 'pinia'

const useOrderStore = defineStore('useOrderStore', {
	unistorage: true,
	state: () => {
		return {
			readOrders: uni.getStorageSync('readOrders') || [] // 初始化从本地存储读取
		}
	},
	actions: {
		// 添加已读订单ID
		addReadOrder(orderId) {
			if (!this.readOrders.includes(orderId)) {
				this.readOrders.push(orderId)
				uni.setStorageSync('readOrders', this.readOrders) // 同步到本地存储
			}
		},
		setIsRead(list) {
			return list.map(item => ({
				...item,
				isRead: this.readOrders.includes(item.orderId)
			}))
		},
		getOrderList(list) {
			return list
		}
	}
})

export default useOrderStore